﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using CARMSData.EntityClasses;

namespace CARMSBusiness.InterFace
{
    public class ApplicationConfiguration
    {
        public const char StringSeperator = '|';

        public static int DataFormatKeyID = 1;
        public static int AdminEmailID = 2;
        public static int DefaultPasswordID = 3;


        public static int MailFromID = 4;
        public static int MailServerAddressID = 5;
        public static int MailUserNameID = 6;
        public static int MailPasswordID = 7;
        public static int MailPortID = 8;


        /// <summary>
        /// 端口
        /// </summary>
        public static int MailPort
        {
            get
            {
                int port = 25;
                if (Int32.TryParse(ConfigBusiness.GetConfiguration(MailPortID), out port))
                {

                }
                return port;
            }
        }

        /// <summary>
        /// 邮件的发件人
        /// </summary>
        public static string MailFrom
        {
            get
            {
                return ConfigBusiness.GetConfiguration(MailFromID);
            }
        }
        /// <summary>
        /// smtp 服务器地址
        /// </summary>
        public static string MailServerAddress
        {
            get
            {
                return ConfigBusiness.GetConfiguration(MailServerAddressID);
            }
        }
        /// <summary>
        /// smtp 用户名
        /// </summary>
        public static string MailUserName
        {
            get
            {
                return ConfigBusiness.GetConfiguration(MailUserNameID);
            }
        }
        /// <summary>
        /// smtp 密码
        /// </summary>
        public static string MailPassword
        {
            get
            {
                return ConfigBusiness.GetConfiguration(MailPasswordID);
            }
        }

        public static string DateFormat
        {
            get
            {
                return ConfigBusiness.GetConfiguration(DataFormatKeyID);
            }
        }
        public static string AdminEmail
        {
            get
            {
                return ConfigBusiness.GetConfiguration(AdminEmailID);
            }
        }

        public static string DefaultPassword
        {
            get
            {
                return ConfigBusiness.GetConfiguration(DefaultPasswordID);
            }
        }

        public static string DateTimeFormat
        {
            get
            {
                return ConfigBusiness.GetConfiguration(DataFormatKeyID) + " HH:mm:ss";
            }
        }

        public static DateTimeFormatInfo DateTimeFormatInfo
        {
            get
            {
                var format = new DateTimeFormatInfo()
                {
                    FullDateTimePattern = DateTimeFormat,
                    ShortDatePattern = DateFormat
                };

                return format;
            }
        }

        public static bool SaveConfiguration(int keyID, string strValue)
        {
            var entity = new ConfigurationEntity(keyID);
            entity.Value = strValue;
            return entity.Save();
        }

    }
}
